package com.netty.swing;

import javax.swing.*;
import java.awt.*;

/**
 * @Description:
 * @Author: yangzhiwei
 * @Date: 2021/8/6 15:19
 */
public class JFrameFixedUtil {
    public static void setDimension(JFrame jFrame) {
        Dimension dimension = new Dimension();
        dimension.setSize(800,800);
        jFrame.setSize(dimension);
    }

    public static void setLocationRelativeTo(JFrame jFrame) {
         // jframe中央位于 屏幕中央
        jFrame.setLocationRelativeTo(null);
    }

    public static void setDimensionAndLocationRelativeTo(JFrame jFrame) {
        // 这里的顺序会影响frame的位置. 如果相对位置在前，则jframe实际的相对位置是左上角为 屏幕中点
        setDimension(jFrame);
        //setLocationRelativeTo(jFrame);

    }

    // 点击关闭按钮的实际
    public static void setDefaultCloseOperation(JFrame jFrame) {
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    //内容窗格对象 设置
    public static void setContentPane(JFrame jFrame) {
        // 内容窗格对象
        Container c = jFrame.getContentPane();
        JLabel jl = new JLabel("这是使用Jframe类创建的窗口");
        c.add(jl);
        System.out.println(c);
    }

    // 设置JF中的JPanel
    public static void setJPanel(JFrame jFrame) {
        JPanel jPanel = new JPanel();
        jPanel.setBackground(Color.white);

        // 在边框布局中,没有被设置到指定区域的标签是不会被显示的
//        JLabel jl = new JLabel("这是放在Jpanel上的标签");
//        jPanel.add(jl);

        //setBorderLayout(jPanel);
        //setGridLayoutDemo(jPanel);
        setFlowLayout(jPanel);
        jFrame.add(jPanel);
    }

    // 边框布局
    public static void setBorderLayout(JPanel jpanel) {
        jpanel.setLayout(new BorderLayout());
        JButton button1=new JButton ("上");
        JButton button2=new JButton("左");
        JButton button3=new JButton("中");
        JButton button4=new JButton("右");
        JButton button5=new JButton("下");
        jpanel.add(button1,BorderLayout.NORTH);
        jpanel.add(button2,BorderLayout.WEST);
        jpanel.add(button3,BorderLayout.CENTER);
        jpanel.add(button4,BorderLayout.EAST);
        jpanel.add(button5,BorderLayout.SOUTH);
        jpanel.setBounds(330,200, 600, 300);
    }

    // 卡片布局
    public static void setCardLayout(JPanel panel) {

    }


    //网格布局
    public static void setGridLayoutDemo(JPanel panel) {
        panel.setLayout(new GridLayout(4,4,5,5));
        panel.add(new JButton("7"));    //添加按钮
        panel.add(new JButton("8"));
        panel.add(new JButton("9"));
        panel.add(new JButton("/"));
        panel.add(new JButton("4"));
        panel.add(new JButton("5"));
        panel.add(new JButton("6"));
        panel.add(new JButton("*"));
        panel.add(new JButton("1"));
        panel.add(new JButton("2"));
        panel.add(new JButton("3"));
        panel.add(new JButton("-"));
        panel.add(new JButton("0"));
        panel.add(new JButton("."));
        panel.add(new JButton("="));
        panel.add(new JButton("+"));
        panel.setBounds(330,200, 600, 300);
    }

    // 网格包

    //流式布局 FlowLayout
    public static void setFlowLayout(JPanel panel) {
        FlowLayout layout = new FlowLayout();
       // layout.setVgap();
        layout.setHgap(80);
        panel.setLayout(layout);
        JButton button1 = new JButton("button1");
        JButton button2 = new JButton("button2");
        JButton button3 = new JButton("button3");
        JButton button4 = new JButton("button4");
        JButton button5 = new JButton("button5");
        panel.add(button1);
        panel.add(button2);
        panel.add(button3);
        panel.add(button4);
        panel.add(button5);
    }

    //盒布局管理



}
